/*===========================================================================+
 |   Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA    |
 |                         All rights reserved.                              |
 +===========================================================================+
 |  HISTORY                                                                  |
 +===========================================================================*/
package sza.oracle.apps.ap.oie.poimport.webui;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;

import oracle.jbo.Row;
import oracle.jbo.ViewObject;

/**
 * Controller for ...
 */
public class ExpenditureOieMappingCO extends OAControllerImpl
{
  public static final String RCS_ID="$Header$";
  public static final boolean RCS_ID_RECORDED =
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

  /**
   * Layout and page setup logic for a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
  }

  /**
   * Procedure to handle form submissions for form elements in
   * a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    if(pageContext.getParameter("AddBtn")!=null){
          OAViewObject vo = (OAViewObject)am.findViewObject("SzaOieExpenditureMapVO1");  
        if (!vo.isPreparedForExecution())    
        {       
            vo.executeQuery();    
        } 
        
           Row row = vo.createRow();    
           vo.insertRow(row);
          row.setNewRowState(Row.STATUS_INITIALIZED);


    } else if(pageContext.getParameter("SaveBtn")!=null){
        am.getTransaction().commit();
    } else if ("delete".equals(pageContext.getParameter(EVENT_PARAM)))
    {
        String mappingId = pageContext.getParameter("mappingId");
        OAViewObject vo = (OAViewObject)am.findViewObject("SzaOieExpenditureMapVO1");  
        Row[] rows = vo.getFilteredRows("MappingId",mappingId);
        for(int i=0;i<rows.length;i++){
            Row row = rows[i];
            row.remove();
        }
        am.getTransaction().commit();
    }
  }

}
